///Project: Introducing GLP Paper Table 5
///Date:14 09 2018 
///Stata14 

******************Table 5*******************************

clear all
use "/Users/erzeno/Dropbox/GLP/JG_EO_Papers/Introducing GLP Paper/Publication/PoP/Submission 2 (Bernhard)/Round 3/Replicationdata/GLP_person_18 07 29.dta"
drop if missing(occupation1)
count
gen temp=1
sort country_nid
by country_nid: egen alloccp=total(temp)
tab occupation1
count
count if power==1
count if power==3
count if office1==2|office2==2|office3==2
count if office1==7|office2==7|office3==7
count if office1==6|office2==6|office3==6
count if wealth==0
count if wealth==1
count if region==1
count if region==2
count if region==3
count if region==4
count if region==5
count if regime==0
count if regime==1

**White collar**
preserve
keep if occupation1==1
sort country_nid
by country_nid: egen whitecol=total(temp) if occupation1==1
gen percentage=whitecol/alloccp*100
collapse (max) percentage, by(country country_nid)
merge m:1 country_nid using  "/Users/erzeno/Dropbox/GLP/JG_EO_Papers/Introducing GLP Paper/Publication/PoP/Submission 2 (Bernhard)/Round 3/Replicationdata/Country_list.dta"
replace percentage=0 if _merge==2
sum percentage
return list
sum percentage if wealth==1
sum percentage if wealth==0
sum percentage if regime==0
sum percentage if regime==1
by region, sort: sum  percentage
restore
*Apex*
preserve
keep if power==1
count
by country_nid: egen whitecol=total(temp) if occupation1==1 
by country_nid: egen all=total(temp)
gen percentage=whitecol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Top ten*
preserve
keep if power==3
count
by country_nid: egen whitecol=total(temp) if occupation1==1 
by country_nid: egen all=total(temp)
gen percentage=whitecol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Cabinet*
preserve
keep if office1==2 |office2==2 |office3==2
count
by country_nid: egen whitecol=total(temp) if occupation1==1 
by country_nid: egen all=total(temp)
gen percentage=whitecol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Supreme Court*
preserve
keep if office1==7 |office2==7 |office3==7
count
by country_nid: egen whitecol=total(temp) if occupation1==1 
by country_nid: egen all=total(temp)
gen percentage=whitecol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*MPs*
preserve
keep if office1==6 |office2==6 |office3==6
count
by country_nid: egen whitecol=total(temp) if occupation1==1 
by country_nid: egen all=total(temp)
gen percentage=whitecol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
//////////////////////////////////////////////////////////
**Blue collar**
preserve
keep if occupation1==2 
sort country_nid
by country_nid: egen blucol=total(temp)
gen percentage=blucol/alloccp*100
duplicates drop country_nid, force
merge m:1 country_nid using  "/Users/erzeno/Dropbox/GLP/JG_EO_Papers/Introducing GLP Paper/Publication/PoP/Submission 2 (Bernhard)/Round 3/Replicationdata/Country_list.dta"
replace percentage=0 if _merge==2
sum percentage
return list
sum percentage if wealth==1
sum percentage if wealth==0
sum percentage if regime==0
sum percentage if regime==1
by region, sort: sum  percentage
restore
*Apex*
preserve
keep if power==1
by country_nid: egen blucol=total(temp) if occupation1==2
by country_nid: egen all=total(temp)
gen percentage=blucol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Top ten*
preserve
keep if power==3
by country_nid: egen blucol=total(temp) if occupation1==2
by country_nid: egen all=total(temp)
gen percentage=blucol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Cabinet*
preserve
keep if office1==2 |office2==2 |office3==2
by country_nid: egen blucol=total(temp) if occupation1==2
by country_nid: egen all=total(temp)
gen percentage=blucol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Supreme Court*
preserve
keep if office1==7 |office2==7 |office3==7
by country_nid: egen blucol=total(temp) if occupation1==2
by country_nid: egen all=total(temp)
gen percentage=blucol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*MPs*
preserve
keep if office1==6 |office2==6 |office3==6
by country_nid: egen blucol=total(temp) if occupation1==2
by country_nid: egen all=total(temp)
gen percentage=blucol/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
////////////////////////////////////////////////////////////////
**Education**
preserve
keep if occupation1==3
sort country_nid
by country_nid: egen edu=total(temp) 
gen percentage=edu/alloccp*100
duplicates drop country_nid, force
merge m:1 country_nid using  "/Users/erzeno/Dropbox/GLP/JG_EO_Papers/Introducing GLP Paper/Publication/PoP/Submission 2 (Bernhard)/Round 3/Replicationdata/Country_list.dta"
replace percentage=0 if _merge==2
sum percentage
return list
sum percentage if wealth==1
sum percentage if wealth==0
sum percentage if regime==0
sum percentage if regime==1
by region, sort: sum  percentage
restore
*Apex*
preserve
keep if power==1
by country_nid: egen edu=total(temp) if occupation1==3
by country_nid: egen all=total(temp)
gen percentage=edu/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Top ten*
preserve
keep if power==3
by country_nid: egen edu=total(temp) if occupation1==3
by country_nid: egen all=total(temp)
gen percentage=edu/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Cabinet*
preserve
keep if office1==2 |office2==2 |office3==2
by country_nid: egen edu=total(temp) if occupation1==3
by country_nid: egen all=total(temp)
gen percentage=edu/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Supreme Court*
preserve
keep if office1==7 |office2==7 |office3==7
by country_nid: egen edu=total(temp) if occupation1==3
by country_nid: egen all=total(temp)
gen percentage=edu/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*MPs*
preserve
keep if office1==6 |office2==6 |office3==6
by country_nid: egen edu=total(temp) if occupation1==3
by country_nid: egen all=total(temp)
gen percentage=edu/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
///////////////////////////////////////////////////////////////
**Media**
preserve
keep if occupation1==4
sort country_nid
by country_nid: egen media=total(temp) 
gen percentage=media/alloccp*100
duplicates drop country_nid, force
merge m:1 country_nid using  "/Users/erzeno/Dropbox/GLP/JG_EO_Papers/Introducing GLP Paper/Publication/PoP/Submission 2 (Bernhard)/Round 3/Replicationdata/Country_list.dta"
replace percentage=0 if _merge==2
sum percentage
return list
sum percentage if wealth==1
sum percentage if wealth==0
sum percentage if regime==0
sum percentage if regime==1
by region, sort: sum  percentage
restore
*Apex*
preserve
keep if power==1
by country_nid: egen media=total(temp) if occupation1==4
by country_nid: egen all=total(temp)
gen percentage=media/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Top ten*
preserve
keep if power==3
by country_nid: egen media=total(temp) if occupation1==4
by country_nid: egen all=total(temp)
gen percentage=media/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Cabinet*
preserve
keep if office1==2 |office2==2 |office3==2
by country_nid: egen media=total(temp) if occupation1==4
by country_nid: egen all=total(temp)
gen percentage=media/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Supreme Court*
preserve
keep if office1==7 |office2==7 |office3==7
by country_nid: egen media=total(temp) if occupation1==4
by country_nid: egen all=total(temp)
gen percentage=media/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*MPs*
preserve
keep if office1==6 |office2==6 |office3==6
by country_nid: egen media=total(temp) if occupation1==4
by country_nid: egen all=total(temp)
gen percentage=media/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
//////////////////////////////////////////////////////////////
**Military**
preserve
keep if occupation1==5
sort country_nid
by country_nid: egen military=total(temp) 
gen percentage=military/alloccp*100
duplicates drop country_nid, force
merge m:1 country_nid using  "/Users/erzeno/Dropbox/GLP/JG_EO_Papers/Introducing GLP Paper/Publication/PoP/Submission 2 (Bernhard)/Round 3/Replicationdata/Country_list.dta"
replace percentage=0 if _merge==2
sum percentage
return list
sum percentage if wealth==1
sum percentage if wealth==0
sum percentage if regime==0
sum percentage if regime==1
by region, sort: sum  percentage
restore
*Apex*
preserve
keep if power==1
by country_nid: egen military=total(temp) if occupation1==5
by country_nid: egen all=total(temp)
gen percentage=military/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Top ten*
preserve
keep if power==3
by country_nid: egen military=total(temp) if occupation1==5
by country_nid: egen all=total(temp)
gen percentage=military/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Cabinet*
preserve
keep if office1==2 |office2==2 |office3==2
by country_nid: egen military=total(temp) if occupation1==5
by country_nid: egen all=total(temp)
gen percentage=military/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Supreme Court*
preserve
keep if office1==7 |office2==7 |office3==7
by country_nid: egen military=total(temp) if occupation1==5
by country_nid: egen all=total(temp)
gen percentage=military/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*MPs*
preserve
keep if office1==6 |office2==6 |office3==6
by country_nid: egen military=total(temp) if occupation1==5
by country_nid: egen all=total(temp)
gen percentage=military/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
///////////////////////////////////////////////////////
**none of pols**
preserve
keep if occupation1==6
sort country_nid
by country_nid: egen nonepols=total(temp) 
gen percentage=nonepols/alloccp*100
duplicates drop country_nid, force
merge m:1 country_nid using  "/Users/erzeno/Dropbox/GLP/JG_EO_Papers/Introducing GLP Paper/Publication/PoP/Submission 2 (Bernhard)/Round 3/Replicationdata/Country_list.dta"
replace percentage=0 if _merge==2
sum percentage
return list
sum percentage if wealth==1
sum percentage if wealth==0
sum percentage if regime==0
sum percentage if regime==1
by region, sort: sum  percentage
restore
*Apex*
preserve
keep if power==1
by country_nid: egen nonepols=total(temp) if occupation1==6
by country_nid: egen all=total(temp)
gen percentage=nonepols/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Top ten*
preserve
keep if power==3
by country_nid: egen nonepols=total(temp) if occupation1==6
by country_nid: egen all=total(temp)
gen percentage=nonepols/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Cabinet*
preserve
keep if office1==2 |office2==2 |office3==2
by country_nid: egen nonepols=total(temp) if occupation1==6
by country_nid: egen all=total(temp)
gen percentage=nonepols/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Supreme Court*
preserve
keep if office1==7 |office2==7 |office3==7
by country_nid: egen nonepols=total(temp) if occupation1==6
by country_nid: egen all=total(temp)
gen percentage=nonepols/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*MPs*
preserve
keep if office1==6 |office2==6 |office3==6
by country_nid: egen nonepols=total(temp) if occupation1==6
by country_nid: egen all=total(temp)
gen percentage=nonepols/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
////////////////////////////////////////////////////////////////////
**Other**
preserve
keep if occupation1==7
sort country_nid
by country_nid: egen other=total(temp) 
gen percentage=other/alloccp*100
duplicates drop country_nid, force
merge m:1 country_nid using  "/Users/erzeno/Dropbox/GLP/JG_EO_Papers/Introducing GLP Paper/Publication/PoP/Submission 2 (Bernhard)/Round 3/Replicationdata/Country_list.dta"
replace percentage=0 if _merge==2
sum percentage
return list
sum percentage if wealth==1
sum percentage if wealth==0
sum percentage if regime==0
sum percentage if regime==1
by region, sort: sum  percentage
restore
*Apex*
preserve
keep if power==1
by country_nid: egen other=total(temp) if occupation1==7
by country_nid: egen all=total(temp)
gen percentage=other/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Top ten*
preserve
keep if power==3
by country_nid: egen other=total(temp) if occupation1==7
by country_nid: egen all=total(temp)
gen percentage=other/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Cabinet*
preserve
keep if office1==2 |office2==2 |office3==2
by country_nid: egen other=total(temp) if occupation1==7
by country_nid: egen all=total(temp)
gen percentage=other/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*Supreme Court*
preserve
keep if office1==7 |office2==7 |office3==7
by country_nid: egen other=total(temp) if occupation1==7
by country_nid: egen all=total(temp)
gen percentage=other/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore
*MPs*
preserve
keep if office1==6 |office2==6 |office3==6
by country_nid: egen other=total(temp) if occupation1==7
by country_nid: egen all=total(temp)
gen percentage=other/all*100
replace percentage=0 if missing(percentage)
collapse (max) percentage, by(country_nid)
sum percentage
restore





